package net.csdn.business.common.utils;

import org.springframework.web.context.request.RequestContextHolder;

import javax.servlet.http.HttpServletRequest;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;

/**
 * @author likun
 * @date 2022/6/17 13:05
 */
public class RequestUtil {
    public static Map<String, String> getQueryMap(HttpServletRequest request) {
        if (request == null || RequestContextHolder.getRequestAttributes() == null) {
            return new HashMap<>();
        }
        Map<String, String> result = new LinkedHashMap<>();
        Enumeration<String> headerNames = request.getParameterNames();
        while (headerNames.hasMoreElements()) {
            String header = headerNames.nextElement();
            String value = request.getParameter(header);
            result.put(header, value);
        }
        return result;
    }
}
